package org.spring.springboot.app.platform.balancelog.controller;

import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.spring.springboot.app.adv.advinfo.domain.vo.AdvInfoCountVO;
import org.spring.springboot.app.adv.advinfo.domain.vo.AdvInfoVO;
import org.spring.springboot.app.base.R;
import org.spring.springboot.app.base.Type;
import org.spring.springboot.app.base.User;
import org.spring.springboot.app.platform.balancelog.domain.po.PlatformBalanceLogPO;
import org.spring.springboot.app.platform.balancelog.domain.vo.*;
import org.spring.springboot.app.platform.balancelog.service.IPlatformBalanceLogService;
import org.spring.springboot.component.annotation.AccessTokenVerify;
import org.spring.springboot.util.ApiIndex;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.text.SimpleDateFormat;
import java.util.*;

@Api(description = "平台收支明细操作接口",tags = ApiIndex.PlatformBalanceLogController)
@RequestMapping(value = "/api/platformbalancelog")
@RestController
public class PlatformBalanceLogController {

    @Autowired
    private IPlatformBalanceLogService platformbalanceLogService;


    @ApiOperation(value = "查询平台收支明细列表-分页")
    @RequestMapping(value = "", method = RequestMethod.GET)
    public R<PageInfo<List<PlatformBalanceLogVO>>> findPageAll(
            @ApiParam(value = "名称", required = false) @RequestParam(defaultValue = "") String name,
            @ApiParam(value = "类型", required = false) @RequestParam(defaultValue = "") String types,
            @ApiParam(value = "类型", required = false) @RequestParam(defaultValue = "") String type,
            @ApiParam(value = "页数", required = true) @RequestParam(defaultValue = "1") int pageNum,
            @ApiParam(value = "每页条数", required = true) @RequestParam(defaultValue = "10") int pageSize,
            @ApiParam(value = "开始创建时间（例如1993-08-11 或者 1993-08-11 00:00:00）", required = false) @RequestParam(defaultValue = "") String startCreateDate,
            @ApiParam(value = "结束创建时间（例如1993-08-11 或者 1993-08-11 23:59:59）", required = false) @RequestParam(defaultValue = "") String endCreateDate
    ) {
        PlatformBalanceLogSearchVO searchvo=new PlatformBalanceLogSearchVO();  //查询对象
        if(StringUtils.isNotBlank(startCreateDate)){
            if(startCreateDate.indexOf(":")==-1){
                startCreateDate=startCreateDate+" 00:00:00";
            }
        }
        if(StringUtils.isNotBlank(endCreateDate)){
            if(endCreateDate.indexOf(":")==-1){
                endCreateDate=endCreateDate+" 23:59:59";
            }
        }
        String[] a = type.split("_");
        searchvo.setStartCreateDate(startCreateDate);
        searchvo.setEndCreateDate(endCreateDate);
        searchvo.setType(a[0]);
        R<PageInfo<List<PlatformBalanceLogVO>>> result = new R<PageInfo<List<PlatformBalanceLogVO>>>();
        List<PlatformBalanceLogPO> _list = platformbalanceLogService.findPage(searchvo,pageNum, pageSize,types);
        PageInfo p =new PageInfo(_list);
        p.setList(getVOS(p.getList()));
        result.setData(p);
        return result;
    }

    private List<PlatformBalanceLogVO> getVOS(List<PlatformBalanceLogPO> _list) {
        List<PlatformBalanceLogVO> list = new ArrayList<PlatformBalanceLogVO>();
        if (_list != null && _list.size()>0) {
            for (PlatformBalanceLogPO po : _list) {
                PlatformBalanceLogVO vo = new PlatformBalanceLogVO();
                BeanUtils.copyProperties(po,vo);
                list.add(vo);
            }
        }
        return list;
    }

    @ApiOperation(value = "根据Id获取单个信息")
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public R<PlatformBalanceLogPO> find(
            @ApiParam(value = "平台收支id", required = true) @PathVariable("id") String id
    ) {
        R<PlatformBalanceLogPO> result = new R<PlatformBalanceLogPO>();
        PlatformBalanceLogPO po = platformbalanceLogService.find(id);
        PlatformBalanceLogPO vo = new PlatformBalanceLogPO();
        BeanUtils.copyProperties(po,vo);
        result.setData(vo);
        return result;
    }




    @ApiOperation(value = "删除平台收支信息")
    @ApiImplicitParam(name = "token", value = "token", paramType = "query", dataType = "String", required = true)
    @AccessTokenVerify
    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
    public R delete(
            @ApiParam(value = "平台收支id", required = true) @PathVariable("id") String id
    ) {
        R result = new R();
        int code = platformbalanceLogService.delete(id);
        if (code == 0) {
            result.setType(Type.OperError);
            result.setMessage("删除失败");
        }
        return result;
    }

    /**
     *  批量删除
     * @param ids
     */
    @ApiOperation(value="批量删除平台收支信息")
    @ApiImplicitParam(name = "token", value = "token", paramType = "query", dataType = "String", required = true)
    @AccessTokenVerify
    @RequestMapping(value = "/deletes", method = RequestMethod.DELETE)
    public R deletes(@ApiParam(value = "平台收支ids(用,分割)", required = true) @RequestParam("ids") String ids) {
        R result = new R();
        int code = platformbalanceLogService.deletes(ids);
        if (code == 0) {
            result.setCode(1);
            result.setMessage("刪除失败");
        }
        return result;
    }



    @ApiOperation(value = "查询用户增长曲线图")
    @RequestMapping(value = "/usercurve", method = RequestMethod.GET)
    @ApiImplicitParam(name = "token", value = "token", paramType = "query", dataType = "String", required = true)
    @AccessTokenVerify
    public R<List<UserVO>> usercurve(
            @ApiIgnore User user
    ){
        boolean one=false;
        boolean two=false;
        boolean three=false;
        boolean four=false;
        boolean five=false;
        boolean six=false;
        boolean serven=false;
        String[] arr=new String[]{"01","02","03","04","05","06","07","08",
          "09","10","11","12","13","14","15","16","17","18","19","20","21",
                "22","23","24","25","26","27","28","29","30","31","32","33","34","35",
        "36","37","38","39","40","41","42","43","44","45","46","47","48","49","50","51","52"};
        R result = new R();
        List<UserVO> _list = platformbalanceLogService.findUser();
        List<UserCountVO> list = platformbalanceLogService.findUserCount();

        //循环判断有那几个星期
        for(UserCountVO hc:list){
            if(hc.getDay().equals(2)){
                one=true;  //周一
            }else if(hc.getDay().equals(3)){
                two=true;  //周二
            }else if(hc.getDay().equals(4)){
                three=true;  //周三
            }else if(hc.getDay().equals(5)){
                four=true;  //周四
            }else if(hc.getDay().equals(6)){
                five=true;  //周五
            }else if(hc.getDay().equals(7)){
                six=true;  //周六
            }else if(hc.getDay().equals(1)){
                serven=true;  //周日
            }
        }

        /*******************************/
        //给星期为空的一条数据
        for(int i=0;i<7-list.size();i++){
            UserVO hv=new UserVO();
            if(one==false){
                hv.setTime("2");
                hv.setTem(0);
                hv.setCity("white");
                _list.add(hv);
                one=true;
            }else if(two==false){
                hv.setTime("3");
                hv.setTem(0);
                hv.setCity("white");
                _list.add(hv);
                two=true;
            }else if(three==false){
                hv.setTime("4");
                hv.setTem(0);
                hv.setCity("white");
                _list.add(hv);
                three=true;
            }else if(four==false){
                hv.setTime("5");
                hv.setTem(0);
                hv.setCity("white");
                _list.add(hv);
                four=true;
            }else if(five==false){
                hv.setTime("6");
                hv.setTem(0);
                hv.setCity("white");
                _list.add(hv);
                five=true;
            }else if(six==false){
                hv.setTime("7");
                hv.setTem(0);
                hv.setCity("white");
                _list.add(hv);
                six=true;
            }else if(serven==false){
                hv.setTime("1");
                hv.setTem(0);
                hv.setCity("white");
                _list.add(hv);
                serven=true;
            }
        }

        SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        //第几周
        int week = calendar.get(Calendar.WEEK_OF_MONTH);
        String s = Integer.toString(week);
        if(s.length()==1){
            s="0"+s;
        }
        for(int i=0;i<arr.length;i++){
            if(s.equals(arr[i])){
                int a=0;
                for(int j=i;j>=-1;j--){
                    a++;
                    if(a==7){
                        break;
                    }
                    if(j==-1){
                        j=51;
                    }
                    if(j==51){
                        i=51;
                    }
                    for(UserVO ho:_list){
                        if(a!=1 && j==51){
                            if(j==i){
                                if(ho.getCity().equals(arr[j])){
                                    ho.setCity("violet");
                                }
                            }else if(j==i-1){
                                if(ho.getCity().equals(arr[j])){
                                    ho.setCity("yellow");
                                }
                            }else if(j==i-2){
                                if(ho.getCity().equals(arr[j])){
                                    ho.setCity("orange");
                                }
                            }else if(j==i-3){
                                if(ho.getCity().equals(arr[j])){
                                    ho.setCity("blue");
                                }
                            }else if(j==i-4){
                                if(ho.getCity().equals(arr[j])){
                                    ho.setCity("red");
                                }
                            }else if(j==i-5){
                                if(ho.getCity().equals(arr[j])){
                                    ho.setCity("green");
                                }
                            }
                        }
                        if(j==i){
                            if(ho.getCity().equals(arr[j])){
                                ho.setCity("newYork");
                            }
                        }else if(j==i-1){
                            if(ho.getCity().equals(arr[j])){
                                ho.setCity("tokyo");
                            }
                        }else if(j==i-2){
                            if(ho.getCity().equals(arr[j])){
                                ho.setCity("berlin");
                            }
                        }else if(j==i-3){
                            if(ho.getCity().equals(arr[j])){
                                ho.setCity("beijing");
                            }
                        }else if(j==i-4){
                            if(ho.getCity().equals(arr[j])){
                                ho.setCity("red");
                            }
                        }else if(j==i-5){
                            if(ho.getCity().equals(arr[j])){
                                ho.setCity("green");
                            }
                        }else if(j==i-6){
                            if(ho.getCity().equals(arr[j])){
                                ho.setCity("black");
                            }
                        }
                    }
                }
            }
        }

        //转换为中式周末
        for(UserVO ho:_list){
            if(ho.getTime().equals("2")){
                ho.setTime("1");
            }else if(ho.getTime().equals("3")){
                ho.setTime("2");
            }else if(ho.getTime().equals("4")){
                ho.setTime("3");
            }else if(ho.getTime().equals("5")){
                ho.setTime("4");
            }else if(ho.getTime().equals("6")){
                ho.setTime("5");
            }else if(ho.getTime().equals("7")){
                ho.setTime("6");
            }else if(ho.getTime().equals("1")){
                ho.setTime("7");
            }
        }
        //周一到周日排序
        Collections.sort(_list,new Comparator<UserVO>(){
            @Override
            public int compare(UserVO o1,UserVO o2) {
                return Integer.valueOf(o1.getTime())- Integer.valueOf(o2.getTime());
            }
        });

        for(UserVO ho:_list){
            if(ho.getTime().equals("1")){
                ho.setTime("周一");
            }else if(ho.getTime().equals("2")){
                ho.setTime("周二");
            }else if(ho.getTime().equals("3")){
                ho.setTime("周三");
            }else if(ho.getTime().equals("4")){
                ho.setTime("周四");
            }else if(ho.getTime().equals("5")){
                ho.setTime("周五");
            }else if(ho.getTime().equals("6")){
                ho.setTime("周六");
            }else if(ho.getTime().equals("7")){
                ho.setTime("周日");
            }
        }
        result.setData(_list);
        return result;
    }


    @ApiOperation(value = "查询代理商增长曲线图")
    @RequestMapping(value = "/officecurve", method = RequestMethod.GET)
    @ApiImplicitParam(name = "token", value = "token", paramType = "query", dataType = "String", required = true)
    @AccessTokenVerify
    public R<List<OfficeVO>> officecurve(
            @ApiIgnore User user
    ){
        boolean one=false;
        boolean two=false;
        boolean three=false;
        boolean four=false;
        boolean five=false;
        boolean six=false;
        boolean serven=false;
        String[] arr=new String[]{"01","02","03","04","05","06","07","08",
                "09","10","11","12","13","14","15","16","17","18","19","20","21",
                "22","23","24","25","26","27","28","29","30","31","32","33","34","35",
                "36","37","38","39","40","41","42","43","44","45","46","47","48","49","50","51","52"};
        R result = new R();
        List<OfficeVO> _list = platformbalanceLogService.findOffice();
        List<OfficeCountVO> list = platformbalanceLogService.findOfficeCount();

        //循环判断有那几个星期
        for(OfficeCountVO hc:list){
            if(hc.getDay().equals(2)){
                one=true;  //周一
            }else if(hc.getDay().equals(3)){
                two=true;  //周二
            }else if(hc.getDay().equals(4)){
                three=true;  //周三
            }else if(hc.getDay().equals(5)){
                four=true;  //周四
            }else if(hc.getDay().equals(6)){
                five=true;  //周五
            }else if(hc.getDay().equals(7)){
                six=true;  //周六
            }else if(hc.getDay().equals(1)){
                serven=true;  //周日
            }
        }

        /*******************************/
        //给星期为空的一条数据
        for(int i=0;i<7-list.size();i++){
            OfficeVO hv=new OfficeVO();
            if(one==false){
                hv.setTime("2");
                hv.setTem(0);
                hv.setCity("white");
                _list.add(hv);
                one=true;
            }else if(two==false){
                hv.setTime("3");
                hv.setTem(0);
                hv.setCity("white");;
                _list.add(hv);
                two=true;
            }else if(three==false){
                hv.setTime("4");
                hv.setTem(0);
                hv.setCity("white");
                _list.add(hv);
                three=true;
            }else if(four==false){
                hv.setTime("5");
                hv.setTem(0);
                hv.setCity("white");
                _list.add(hv);
                four=true;
            }else if(five==false){
                hv.setTime("6");
                hv.setTem(0);
                hv.setCity("white");
                _list.add(hv);
                five=true;
            }else if(six==false){
                hv.setTime("7");
                hv.setTem(0);
                hv.setCity("white");
                _list.add(hv);
                six=true;
            }else if(serven==false){
                hv.setTime("1");
                hv.setTem(0);
                hv.setCity("white");
                _list.add(hv);
                serven=true;
            }
        }

        SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        //第几周
        int week = calendar.get(Calendar.WEEK_OF_MONTH);
        String s = Integer.toString(week);
        if(s.length()==1){
            s="0"+s;
        }
        for(int i=0;i<arr.length;i++){
            if(s.equals(arr[i])){
                int a=0;
                for(int j=i;j>=-1;j--){
                    a++;
                    if(a==7){
                        break;
                    }
                    if(j==-1){
                        j=51;
                    }
                    if(j==51){
                        i=51;
                    }
                    for(OfficeVO ho:_list){
                        if(a!=1 && j==51){
                            if(j==i){
                                if(ho.getCity().equals(arr[j])){
                                    ho.setCity("violet");
                                }
                            }else if(j==i-1){
                                if(ho.getCity().equals(arr[j])){
                                    ho.setCity("yellow");
                                }
                            }else if(j==i-2){
                                if(ho.getCity().equals(arr[j])){
                                    ho.setCity("orange");
                                }
                            }else if(j==i-3){
                                if(ho.getCity().equals(arr[j])){
                                    ho.setCity("blue");
                                }
                            }else if(j==i-4){
                                if(ho.getCity().equals(arr[j])){
                                    ho.setCity("red");
                                }
                            }else if(j==i-5){
                                if(ho.getCity().equals(arr[j])){
                                    ho.setCity("green");
                                }
                            }
                        }
                        if(j==i){
                            if(ho.getCity().equals(arr[j])){
                                ho.setCity("newYork");
                            }
                        }else if(j==i-1){
                            if(ho.getCity().equals(arr[j])){
                                ho.setCity("tokyo");
                            }
                        }else if(j==i-2){
                            if(ho.getCity().equals(arr[j])){
                                ho.setCity("berlin");
                            }
                        }else if(j==i-3){
                            if(ho.getCity().equals(arr[j])){
                                ho.setCity("beijing");
                            }
                        }else if(j==i-4){
                            if(ho.getCity().equals(arr[j])){
                                ho.setCity("red");
                            }
                        }else if(j==i-5){
                            if(ho.getCity().equals(arr[j])){
                                ho.setCity("green");
                            }
                        }else if(j==i-6){
                            if(ho.getCity().equals(arr[j])){
                                ho.setCity("black");
                            }
                        }
                    }
                }
            }
        }

        //转换为中式周末
        for(OfficeVO ho:_list){
            if(ho.getTime().equals("2")){
                ho.setTime("1");
            }else if(ho.getTime().equals("3")){
                ho.setTime("2");
            }else if(ho.getTime().equals("4")){
                ho.setTime("3");
            }else if(ho.getTime().equals("5")){
                ho.setTime("4");
            }else if(ho.getTime().equals("6")){
                ho.setTime("5");
            }else if(ho.getTime().equals("7")){
                ho.setTime("6");
            }else if(ho.getTime().equals("1")){
                ho.setTime("7");
            }
        }
        //周一到周日排序
        Collections.sort(_list,new Comparator<OfficeVO>(){
            @Override
            public int compare(OfficeVO o1,OfficeVO o2) {
                return Integer.valueOf(o1.getTime())- Integer.valueOf(o2.getTime());
            }
        });

        for(OfficeVO ho:_list){
            if(ho.getTime().equals("1")){
                ho.setTime("周一");
            }else if(ho.getTime().equals("2")){
                ho.setTime("周二");
            }else if(ho.getTime().equals("3")){
                ho.setTime("周三");
            }else if(ho.getTime().equals("4")){
                ho.setTime("周四");
            }else if(ho.getTime().equals("5")){
                ho.setTime("周五");
            }else if(ho.getTime().equals("6")){
                ho.setTime("周六");
            }else if(ho.getTime().equals("7")){
                ho.setTime("周日");
            }
        }
        result.setData(_list);
        return result;
    }



    @ApiOperation(value = "查询平台收益增长曲线图")
    @RequestMapping(value = "/balancecurve", method = RequestMethod.GET)
    @ApiImplicitParam(name = "token", value = "token", paramType = "query", dataType = "String", required = true)
    @AccessTokenVerify
    public R<List<BalanceVO>> balancecurve(
            @ApiIgnore User user
    ){
        boolean one=false;
        boolean two=false;
        boolean three=false;
        boolean four=false;
        boolean five=false;
        boolean six=false;
        boolean serven=false;
        String[] arr=new String[]{"01","02","03","04","05","06","07","08",
                "09","10","11","12","13","14","15","16","17","18","19","20","21",
                "22","23","24","25","26","27","28","29","30","31","32","33","34","35",
                "36","37","38","39","40","41","42","43","44","45","46","47","48","49","50","51","52"};
        R result = new R();
        List<BalanceVO> _list = platformbalanceLogService.findBalance();
        List<BalanceCountVO> list = platformbalanceLogService.findBalanceCount();

        //循环判断有那几个星期
        for(BalanceCountVO hc:list){
            if(hc.getDay().equals(2)){
                one=true;  //周一
            }else if(hc.getDay().equals(3)){
                two=true;  //周二
            }else if(hc.getDay().equals(4)){
                three=true;  //周三
            }else if(hc.getDay().equals(5)){
                four=true;  //周四
            }else if(hc.getDay().equals(6)){
                five=true;  //周五
            }else if(hc.getDay().equals(7)){
                six=true;  //周六
            }else if(hc.getDay().equals(1)){
                serven=true;  //周日
            }
        }

        /*******************************/
        //给星期为空的一条数据
        for(int i=0;i<7-list.size();i++){
            BalanceVO hv=new BalanceVO();
            if(one==false){
                hv.setTime("2");
                hv.setTem(0);
                hv.setCity("white");
                _list.add(hv);
                one=true;
            }else if(two==false){
                hv.setTime("3");
                hv.setTem(0);
                hv.setCity("white");
                _list.add(hv);
                two=true;
            }else if(three==false){
                hv.setTime("4");
                hv.setTem(0);
                hv.setCity("white");
                _list.add(hv);
                three=true;
            }else if(four==false){
                hv.setTime("5");
                hv.setTem(0);
                hv.setCity("white");
                _list.add(hv);
                four=true;
            }else if(five==false){
                hv.setTime("6");
                hv.setTem(0);
                hv.setCity("white");
                _list.add(hv);
                five=true;
            }else if(six==false){
                hv.setTime("7");
                hv.setTem(0);
                hv.setCity("white");
                _list.add(hv);
                six=true;
            }else if(serven==false){
                hv.setTime("1");
                hv.setTem(0);
                hv.setCity("white");
                _list.add(hv);
                serven=true;
            }
        }

        SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        //第几周
        int week = calendar.get(Calendar.WEEK_OF_MONTH);
        String s = Integer.toString(week);
        if(s.length()==1){
            s="0"+s;
        }
        for(int i=0;i<arr.length;i++){
            if(s.equals(arr[i])){
                int a=0;
                for(int j=i;j>=-1;j--){
                    a++;
                    if(a==7){
                        break;
                    }
                    if(j==-1){
                        j=51;
                    }
                    if(j==51){
                        i=51;
                    }
                    for(BalanceVO ho:_list){
                        if(a!=1 && j==51){
                            if(j==i){
                                if(ho.getCity().equals(arr[j])){
                                    ho.setCity("violet");
                                }
                            }else if(j==i-1){
                                if(ho.getCity().equals(arr[j])){
                                    ho.setCity("yellow");
                                }
                            }else if(j==i-2){
                                if(ho.getCity().equals(arr[j])){
                                    ho.setCity("orange");
                                }
                            }else if(j==i-3){
                                if(ho.getCity().equals(arr[j])){
                                    ho.setCity("blue");
                                }
                            }else if(j==i-4){
                                if(ho.getCity().equals(arr[j])){
                                    ho.setCity("red");
                                }
                            }else if(j==i-5){
                                if(ho.getCity().equals(arr[j])){
                                    ho.setCity("green");
                                }
                            }
                        }
                        if(j==i){
                            if(ho.getCity().equals(arr[j])){
                                ho.setCity("newYork");
                            }
                        }else if(j==i-1){
                            if(ho.getCity().equals(arr[j])){
                                ho.setCity("tokyo");
                            }
                        }else if(j==i-2){
                            if(ho.getCity().equals(arr[j])){
                                ho.setCity("berlin");
                            }
                        }else if(j==i-3){
                            if(ho.getCity().equals(arr[j])){
                                ho.setCity("beijing");
                            }
                        }else if(j==i-4){
                            if(ho.getCity().equals(arr[j])){
                                ho.setCity("red");
                            }
                        }else if(j==i-5){
                            if(ho.getCity().equals(arr[j])){
                                ho.setCity("green");
                            }
                        }else if(j==i-6){
                            if(ho.getCity().equals(arr[j])){
                                ho.setCity("black");
                            }
                        }
                    }
                }
            }
        }

        //转换为中式周末
        for(BalanceVO ho:_list){
            if(ho.getTime().equals("2")){
                ho.setTime("1");
            }else if(ho.getTime().equals("3")){
                ho.setTime("2");
            }else if(ho.getTime().equals("4")){
                ho.setTime("3");
            }else if(ho.getTime().equals("5")){
                ho.setTime("4");
            }else if(ho.getTime().equals("6")){
                ho.setTime("5");
            }else if(ho.getTime().equals("7")){
                ho.setTime("6");
            }else if(ho.getTime().equals("1")){
                ho.setTime("7");
            }
        }
        //周一到周日排序
        Collections.sort(_list,new Comparator<BalanceVO>(){
            @Override
            public int compare(BalanceVO o1,BalanceVO o2) {
                return Integer.valueOf(o1.getTime())- Integer.valueOf(o2.getTime());
            }
        });

        for(BalanceVO ho:_list){
            if(ho.getTime().equals("1")){
                ho.setTime("周一");
            }else if(ho.getTime().equals("2")){
                ho.setTime("周二");
            }else if(ho.getTime().equals("3")){
                ho.setTime("周三");
            }else if(ho.getTime().equals("4")){
                ho.setTime("周四");
            }else if(ho.getTime().equals("5")){
                ho.setTime("周五");
            }else if(ho.getTime().equals("6")){
                ho.setTime("周六");
            }else if(ho.getTime().equals("7")){
                ho.setTime("周日");
            }
        }
        result.setData(_list);
        return result;
    }



    @ApiOperation(value = "查询广告投放数量增长曲线图")
    @RequestMapping(value = "/advcurve", method = RequestMethod.GET)
    @ApiImplicitParam(name = "token", value = "token", paramType = "query", dataType = "String", required = true)
    @AccessTokenVerify
    public R<List<AdvVO>> advcurve(
            @ApiIgnore User user
    ){
        boolean one=false;
        boolean two=false;
        boolean three=false;
        boolean four=false;
        boolean five=false;
        boolean six=false;
        boolean serven=false;
        String[] arr=new String[]{"01","02","03","04","05","06","07","08",
                "09","10","11","12","13","14","15","16","17","18","19","20","21",
                "22","23","24","25","26","27","28","29","30","31","32","33","34","35",
                "36","37","38","39","40","41","42","43","44","45","46","47","48","49","50","51","52"};
        R result = new R();
        List<AdvVO> _list = platformbalanceLogService.findAdv();
        List<AdvCountVO> list = platformbalanceLogService.findAdvCount();

        //循环判断有那几个星期
        for(AdvCountVO hc:list){
            if(hc.getDay().equals(2)){
                one=true;  //周一
            }else if(hc.getDay().equals(3)){
                two=true;  //周二
            }else if(hc.getDay().equals(4)){
                three=true;  //周三
            }else if(hc.getDay().equals(5)){
                four=true;  //周四
            }else if(hc.getDay().equals(6)){
                five=true;  //周五
            }else if(hc.getDay().equals(7)){
                six=true;  //周六
            }else if(hc.getDay().equals(1)){
                serven=true;  //周日
            }
        }

        /*******************************/
        //给星期为空的一条数据
        for(int i=0;i<7-list.size();i++){
            AdvVO hv=new AdvVO();
            if(one==false){
                hv.setTime("2");
                hv.setTem(0);
                hv.setCity("white");
                _list.add(hv);
                one=true;
            }else if(two==false){
                hv.setTime("3");
                hv.setTem(0);
                hv.setCity("white");
                _list.add(hv);
                two=true;
            }else if(three==false){
                hv.setTime("4");
                hv.setTem(0);
                hv.setCity("white");
                _list.add(hv);
                three=true;
            }else if(four==false){
                hv.setTime("5");
                hv.setTem(0);
                hv.setCity("white");
                _list.add(hv);
                four=true;
            }else if(five==false){
                hv.setTime("6");
                hv.setTem(0);
                hv.setCity("white");
                _list.add(hv);
                five=true;
            }else if(six==false){
                hv.setTime("7");
                hv.setTem(0);
                hv.setCity("white");
                _list.add(hv);
                six=true;
            }else if(serven==false){
                hv.setTime("1");
                hv.setTem(0);
                hv.setCity("white");
                _list.add(hv);
                serven=true;
            }
        }

        SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        //第几周
        int week = calendar.get(Calendar.WEEK_OF_MONTH);
        String s = Integer.toString(week);
        if(s.length()==1){
            s="0"+s;
        }
        for(int i=0;i<arr.length;i++){
            if(s.equals(arr[i])){
                int a=0;
                for(int j=i;j>=-1;j--){
                    a++;
                    if(a==7){
                        break;
                    }
                    if(j==-1){
                        j=51;
                    }
                    if(j==51){
                        i=51;
                    }
                    for(AdvVO ho:_list){
                        if(a!=1 && j==51){
                            if(j==i){
                                if(ho.getCity().equals(arr[j])){
                                    ho.setCity("violet");
                                }
                            }else if(j==i-1){
                                if(ho.getCity().equals(arr[j])){
                                    ho.setCity("yellow");
                                }
                            }else if(j==i-2){
                                if(ho.getCity().equals(arr[j])){
                                    ho.setCity("orange");
                                }
                            }else if(j==i-3){
                                if(ho.getCity().equals(arr[j])){
                                    ho.setCity("blue");
                                }
                            }else if(j==i-4){
                                if(ho.getCity().equals(arr[j])){
                                    ho.setCity("red");
                                }
                            }else if(j==i-5){
                                if(ho.getCity().equals(arr[j])){
                                    ho.setCity("green");
                                }
                            }
                        }
                        if(j==i){
                            if(ho.getCity().equals(arr[j])){
                                ho.setCity("newYork");
                            }
                        }else if(j==i-1){
                            if(ho.getCity().equals(arr[j])){
                                ho.setCity("tokyo");
                            }
                        }else if(j==i-2){
                            if(ho.getCity().equals(arr[j])){
                                ho.setCity("berlin");
                            }
                        }else if(j==i-3){
                            if(ho.getCity().equals(arr[j])){
                                ho.setCity("beijing");
                            }
                        }else if(j==i-4){
                            if(ho.getCity().equals(arr[j])){
                                ho.setCity("red");
                            }
                        }else if(j==i-5){
                            if(ho.getCity().equals(arr[j])){
                                ho.setCity("green");
                            }
                        }else if(j==i-6){
                            if(ho.getCity().equals(arr[j])){
                                ho.setCity("black");
                            }
                        }
                    }
                }
            }
        }

        //转换为中式周末
        for(AdvVO ho:_list){
            if(ho.getTime().equals("2")){
                ho.setTime("1");
            }else if(ho.getTime().equals("3")){
                ho.setTime("2");
            }else if(ho.getTime().equals("4")){
                ho.setTime("3");
            }else if(ho.getTime().equals("5")){
                ho.setTime("4");
            }else if(ho.getTime().equals("6")){
                ho.setTime("5");
            }else if(ho.getTime().equals("7")){
                ho.setTime("6");
            }else if(ho.getTime().equals("1")){
                ho.setTime("7");
            }
        }
        //周一到周日排序
        Collections.sort(_list,new Comparator<AdvVO>(){
            @Override
            public int compare(AdvVO o1,AdvVO o2) {
                return Integer.valueOf(o1.getTime())- Integer.valueOf(o2.getTime());
            }
        });

        for(AdvVO ho:_list){
            if(ho.getTime().equals("1")){
                ho.setTime("周一");
            }else if(ho.getTime().equals("2")){
                ho.setTime("周二");
            }else if(ho.getTime().equals("3")){
                ho.setTime("周三");
            }else if(ho.getTime().equals("4")){
                ho.setTime("周四");
            }else if(ho.getTime().equals("5")){
                ho.setTime("周五");
            }else if(ho.getTime().equals("6")){
                ho.setTime("周六");
            }else if(ho.getTime().equals("7")){
                ho.setTime("周日");
            }
        }
        result.setData(_list);
        return result;
    }


}
